<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        canvas {
            border: 1px solid red;
            display: block;
            margin: 100px auto;
            background-image: url(./images/12.png);
            background-size: 100% 100%;
        }
    </style>
</head>

<body>
    <canvas width="500px" height="500px"></canvas>
</body>
<script>
    var convas = document.querySelector("canvas");
    var paint = convas.getContext("2d");
    paint.fillRect(0, 0, 500, 500)

    paint.globalCompositeOperation = "destination-out";
    convas.onmousedown = function (e) {
        paint.beginPath();
        console.log(111)
        x = e.pageX - convas.offsetLeft;
        y = e.pageY - convas.offsetTop;
        paint.fillStyle = "pink"
        console.log(x, y)
        paint.arc(x, y, 20, 0, 360 / 180 * Math.PI, false);
        paint.fill()
        this.flag = true;
    }
    convas.onmousemove = function (e) {
        if (this.flag) {
            paint.beginPath();
            x = e.pageX - convas.offsetLeft;
            y = e.pageY - convas.offsetTop;
            paint.fillStyle = "pink"
            console.log(x, y)
            paint.arc(x, y, 20, 0, 360 / 180 * Math.PI, false);
            paint.fill()
        }
    }
    document.onmouseup = function () {
        convas.flag = false;
    }
</script>

</html>